
$(document).ready(function(){
    // render
    loadData();
    // event
    bindEventEdit();
});

function loadData() {
    var _maMau = ISS.SESSION.getSession('session_maMau');

    var color = {};
    color.maMau = _maMau;
    ISS.BACKEND.request({
        url: ISS.SESSION.getSession('contextPath') + '/service/admin/editProductColor',
        headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/json'
        },
        type: 'POST',
        dataType: 'json',
        data: JSON.stringify(color),
        success: function (data) {
            var responseContent = data.responseObject;
            loadDataComplete(responseContent);
        }
    });
}

function loadDataComplete(color){
    ISS.DOM.setVal('#RegeditFormColor_code', color.maMau);
    ISS.DOM.setVal('#RegeditFormColor_name', color.tenMau);
}

function bindEventEdit(){
    ISS.EVENT.bindEvent('#RegeditFormEdit_color_Modified', 'click', function () {
        sendInfoEdit();
    });
}

function sendInfoEdit() {
    var color = {};
    color.maMau = ISS.DOM.getVal('#RegeditFormColor_code');
    color.tenMau = ISS.DOM.getVal('#RegeditFormColor_name');

    ISS.BACKEND.request({
        url: ISS.SESSION.getSession('contextPath') + '/service/admin/registerColorEdit',
        headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/json'
        },
        type: 'POST',
        dataType: 'json',
        data: JSON.stringify(color),
        success: function (data) {
            var responseContent = data.responseObject;
            sendInfoEditComplete(responseContent);
        }
    });
}

function sendInfoEditComplete(color) {
    if(color) {
        alert('Cập nhật thành công');
        ISS.WINDOW.location('/jsp/admin/ad-product-color-common.jsp');
    }
    else{
        alert('Cập nhật không thành công');
    }
}
